package net.lainiao.zhihu.service;

import net.lainiao.zhihu.common.Common;
import net.lainiao.zhihu.common.MyPage;
import net.lainiao.zhihu.dao.QutuMapper;
import net.lainiao.zhihu.model.Qutu;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import javax.annotation.Resource;
import java.util.List;

/**
 * Created by Administrator on 2016/1/19.
 */
@Service
public class QutuService {
    @Resource
    private QutuMapper qutuMapper;
    private List<Qutu> all;

    public List<Qutu> getPage(MyPage myPage) {
        return qutuMapper.getPage(myPage);
    }

    public Qutu info(String id) {
        return qutuMapper.selectByPrimaryKey(id);
    }

    public int dels(String ids) {
        String[] strs = ids.split(",");
        if (strs.length == 0) {
            return 0;
        }
        return qutuMapper.dels(strs);
    }

    public int save(Qutu qutu) {
        boolean isadd = false;
        if (StringUtils.isEmpty(qutu.getId())) {
            isadd = true;
            qutu.setId(Common.getNewUUID());
            qutu.setStatus(0);
        }
        if (isadd) {
            return qutuMapper.insert(qutu);
        }
        return qutuMapper.updateByPrimaryKey(qutu);
    }

    public List<Qutu> getAll() {
        return qutuMapper.getAll();
    }
}
